package drg_group.wuxi_2022.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.wuxi_2022.Base;
import drg_group.wuxi_2022.MedicalRecord;
import drg_group.wuxi_2022.ADRG.*;

public class MDCM{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"Q55.502","Q55.100x002","Q55.602","D29.401","I89.000x024","N46.x02","D07.602","Q55.600x008","C63.201","Q55.400x006","N49.202","N49.800","T83.600","N40.x00","N48.301","Q54.100","S37.804","C79.818","N44.x01","E29.001","D40.000x001","E89.501","N48.500","I89.000x023","N48.204","N50.817","Q55.201","E29.100x004","N50.800x016","D40.900x001","N48.812","N45.906","N50.818","N49.002","N49.900","N43.201","S38.200x004","N45.002","N50.813","Q85.900x047","N45.905","D17.700x034","D40.100x002","N50.800x002","C79.800x233","N50.824","Q55.403","Q55.402","N48.805","C63.702","N42.200","D40.700x001","B26.000+N51.1*","Q56.300","Q53.100","D40.001","C79.816","Q53.000x002","D40.700x003","Q55.200x901","C60.200","N43.302","N50.819","C62.901","R86.600","N50.806","R86.200","N50.814","D29.001","N49.201","R86.903","C60.100","E29.000","S39.900x007","N48.807","A54.204+N51.1*","D07.401","E29.100","N45.001","N42.300","R86.000","D18.108","N50.803","Q53.102","D29.700x005","Q55.002","A56.102+N51.1*","Q55.606","N48.802","I86.101","Q53.901","Q53.200","S37.802","N48.813","Q54.200","N41.900x002","N50.800x024","E29.104","N41.000","N48.203","D29.700x004","D29.703","C63.100","N50.102","N50.809","N42.101","T83.601","D40.703","S31.300x001","N42.000","C62.100","N48.901","N50.800x038","N40.x01","N50.820","Q55.605","N48.801","N42.802","N48.810","N49.101","N48.202","N50.800x041","N48.403","C63.700","N48.400x007","Q55.800","C60.201","S38.200x005","A18.100x020+N51.8*","N50.800x014","C60.900","D29.701","C61.x00","N50.900x006","N43.001","S39.900x009","N48.000x003","N50.815","Q53.202","A60.003+N51.8*","D40.702","N50.811","Q55.004","Q55.405","E29.105","A59.000x003+N51.0*","A18.109+N51.0*","N49.205","N43.300","Z31.000x004","Q85.900x032","N50.800x028","N50.810","A18.110+N51.8*","N50.800x025","Q53.101","N48.102","N48.800x005","N50.801","N47.x03","N41.100","N48.600","I89.008","S39.904","D40.101","N50.900x007","D29.702","N41.200","N48.809","C79.800x228","N48.808","Q54.001","Q53.000","N50.804","Q55.601","A56.103+N51.1*","Q55.003","Q56.100","N50.800x027","S37.801","R86.100","N50.821","A18.117+N51.1*","N50.808","C60.800","N50.900x008","N44.x00","Q53.201","N48.400x008","R86.800","S38.200x003","E29.000x002","D29.100","S38.000","Q55.600x009","N45.902","N50.823","Q54.300","S39.900x010","N43.400","N49.103","C62.000","N36.801","Q54.901","N48.400","Q56.002","Q55.101","N50.822","N50.825","D29.000","Q53.100x001","R86.400","Z41.200","R86.900x003","N43.000","N48.400x006","N47.x02","N50.101","Q55.300","Q55.501","S31.501","A18.116+N51.8*","C79.800x231","N45.904","N50.103","I89.000x025","N50.807","Q56.001","S30.206","N50.816","A54.203+N51.1*","N41.300","Q55.801","E29.103","D29.900","N49.204","Q53.902","T19.800x002","I86.200","Q55.600x007","N48.806","N50.000","Q54.900","N47.x01","I86.100","A18.118+N51.1*","N43.100","N45.903","Q53.900","N42.801","N45.901","D18.000x815","E29.100x002","D48.127","D40.901","C60.901","E29.900","Q53.200x001","N46.x00","R86.902","E29.106","D29.200","D29.400","A18.100x018+N51.8*","Q55.401","A18.119+N51.8*","Q54.800","C79.815","I87.120","D17.700x033","N49.102","S30.208","N45.907","R86.901","N48.400x005","D40.701","Q54.000","Q55.604","S31.200","S31.300x002","N50.805","N42.901","N48.401","E29.002","D07.400","Q55.901","E29.102","N47.x00x001","S30.203","A60.000x004+N51.8*","N48.800x009","D40.704","C63.000","R93.802","D40.700x002","N50.826","A54.202+N51.0*","S38.001","D07.500","C79.820","C79.819","D29.300","N48.804","N50.901","D18.000x855","I87.804","N41.101","N41.900x001","Q54.400","N46.x00x007","C62.900","C63.801","D17.600x001","Q55.400x008","N50.812","N50.802","C62.001","N50.902","N42.102","Q55.802","N50.827","Q55.603","N49.001","N48.300","N50.100x001","N50.800x012","I89.000x022","C63.701","S30.205","C63.200","A06.800x004+N51.2*","N43.301","N44.x02","N46.x01","S37.910","N48.402","R86.700","T83.401","N50.903","D07.601","N48.001","N49.203","D07.603","Q55.202","I89.800x010","C63.900","D18.000x818","N45.908","N48.000","Q55.203","Q56.400","N43.101","N48.101","Q53.000x003","N49.104","N45.000","N42.301","R86.500","N48.803","Q55.900","N50.800x023","N48.201","Q55.404","E29.101","B37.402+N51.2*","C79.817","Q55.001","S31.301","Q56.000","Q55.800x001","N50.900x005","E29.800","D07.402","N41.800","N48.100","C63.800","N50.800x042","S37.811","S30.202","N50.800","N50.800x001","R86.300","N48.811","C60.000"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]) && record.gender!=null && record.gender.equals("1"))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCM入组条件，匹配规则：主诊断匹配、男性");
        String result;

        result=MA1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MB1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MC1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MD1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MJ1.group(record);
        if (result.length()>0){
            return result;
        }

        if (record.ssList!=null && record.ssList.length>0  && Base.intersect(Base.SS_VALID,record.ssList)){
            Base.groupMessages.putMessage(record.Index,"符合MQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "MQY";
        }

        result=MR1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MS1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MZ1.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCM的ADRG入组条件");
        return "";
    }
}

